<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>通达快递 TDCargo-通行天下,使命必达</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
</head>
<body>
<div class="layui-fluid" style="padding: 15px;">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="test-table-reload-btn" style="margin-bottom: 10px;">
                <form id="usr-receiver-list-query-form" class="layui-form">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">姓名</label>
                            <div class="layui-input-inline">
                                <input name="receiverName" type="text" class="layui-input"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button id="usr-receiver-list-query-btn" class="layui-btn" lay-submit lay-filter="usr-receiver-list-query-submit">查询</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>

            <table class="layui-hide" id="usr-receiver-list-table" lay-filter="usr-receiver-list-table"></table>
        </div>
    </div>
</div>
<script type="text/html" id="usr-receiver-table-tpl">
    <a class="layui-btn layui-btn-xs" lay-event="choose">选择</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
</script>

<script src="/layui/layui.js"></script>
<script>
    layui.config({
        base: '/src/',
        version: new Date().getTime()
    }).extend({setter: "config", admin: "lib/admin", view: "lib/view"})
        .define(['setter', 'admin', 'table', "form"], function () {
            var $ = layui.$,
                admin = layui.admin,
                form = layui.form,
                table = layui.table;

            table.render({
                elem: '#usr-receiver-list-table',
                url: '/usr/listUsrReceiver',
                cols: [[
                    {field: 'name', title: '姓名'},
                    {field: 'telphone', title: '电话'},
                    {field: 'province', title: '省份', hide: true},
                    {field: 'provinceName', title: '省份'},
                    {field: 'city', title: '城市', hide: true},
                    {field: 'cityName', title: '城市'},
                    {field: 'addr', title: '地址'},
                    {field: 'postcode', title: '邮编'},
                    {field: 'idCard', title: '身份证号'},
                    {field: 'idCardFront', title: '身份证号正面', hide: true},
                    {field: 'idCardBack', title: '身份证号反面', hide: true},
                    {title: '操作', width: 120, templet: "#usr-receiver-table-tpl"}
                ]],
                page: true,
                limit: 8,
                where: {
                    access_token: layui.data('layuiAdmin').access_token
                }
            });

            table.on("tool(usr-receiver-list-table)", function (obj) {
                if (obj.event === "choose") {
                    var data = obj.data;
                    parent.layui.$("#bil-express-add-form input[name=receiverName]").val(data.name);
                    parent.layui.$("#bil-express-add-form input[name=receiverTelphone]").val(data.telphone);
                    // parent.layui.$("#bil-express-add-form input[name=city]").val(data.city);
                    parent.layui.$("#bil-express-add-form input[name=receiverAddr]").val(data.addr);
                    parent.layui.$("#bil-express-add-form input[name=postcode]").val(data.postcode);
                    parent.layui.$("#bil-express-add-form input[name=idCard]").val(data.idCard);
                    // parent.layui.$("#bil-express-add-form select[name=province]").val(data.province);
                    parent.layui.$("#bil-express-add-form input[name=provincehid]").val(data.province);
                    parent.layui.$("#bil-express-add-form input[name=cityhid]").val(data.city);
                    // parent.layui.$("#bil-express-add-form select[name=province]").trigger("change");

                    if (data.idCardFront && data.idCardFront.length !== 0) {
                        parent.layui.$("#bil-express-add").trigger("uploadIdCardFront", data.idCardFront);
                    }

                    if (data.idCardBack && data.idCardBack.length !== 0) {
                        parent.layui.$("#bil-express-add").trigger("uploadIdCardBack", data.idCardBack);
                    }

                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                } else{
                    layer.confirm('确定要删除吗?', {icon: 3, title: '提示'}, function (index) {
                        layer.close(index);

                        var data = {"id": obj.data.id};
                        admin.req({
                            url: "/usr/deleteUsrReceiver",
                            data: data,
                            beforeSend: function () {
                                layer.load(2, {time: 100 * 1000});
                            },
                            complete: function () {
                                layer.closeAll('loading');
                            },
                            done: function () {
                                $("#usr-receiver-list-query-btn").trigger("click");
                            }
                        });
                    });
                }
            });

            form.on("submit(usr-receiver-list-query-submit)", function (obj) {
                layer.load(2, {time: 100 * 1000});

                var data = obj.field;
                data["access_token"] = layui.data('layuiAdmin').access_token;

                table.reload("usr-receiver-list-table", {
                    where: data,
                    done: function () {
                        layer.closeAll('loading');
                    }
                });

                return false;
            });
        });
</script>
</body>
</html>